package com.tpc.client.modules.core.organisation;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.grid.events.CellContextClickEvent;
import com.tpc.client.modules.core.organisation.datasource.OrganisationFormDS;
import com.tpc.client.modules.core.organisation.datasource.OrganisationListDS;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.ResultSet;
import com.smartgwt.client.data.events.DataArrivedEvent;
import com.smartgwt.client.data.events.DataArrivedHandler;
import com.smartgwt.client.widgets.grid.events.CellClickEvent;
import com.smartgwt.client.widgets.grid.events.FilterEditorSubmitEvent;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.events.ItemKeyPressEvent;
import com.smartgwt.client.widgets.form.events.ItemKeyPressHandler;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
import com.smartgwt.client.widgets.form.fields.HiddenItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.form.fields.SubmitItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.ToolbarItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.grid.HoverCustomizer;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.CellClickHandler;
import com.smartgwt.client.widgets.grid.events.CellContextClickHandler;
import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent;
import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler;
import com.smartgwt.client.widgets.grid.events.FilterEditorSubmitHandler;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuButton;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.MenuItemSeparator;
import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.util.BooleanCallback; 
import com.tpc.client.systeme.core.Systeme;
import com.tpc.client.systeme.core.TPCT_MODULE;

/**
 * @version 0.0.1
 * @author frederic.fortin
 * @modified 2010-08-15
 */

public class OrganisationUI implements TPCT_MODULE {
    Systeme systeme;
    String MODULEID;
    
    Canvas cnvEmpty = new Canvas();
    
    ListGrid GRID_LIST = new ListGrid();    
    DynamicForm FORM_EDIT = new DynamicForm();

    OrganisationListDS LIST_DS = null;
    OrganisationFormDS FORM_DS = null;
        
    Boolean isUiLoaded = false;
    Boolean isListBuild = false;
    Boolean isListFetch = false;
    Boolean isFormBuild = false;
    Boolean isFormFetch = false;

    TabSet tabS_mini = new TabSet();
    
    int itemId = -1;

    public Canvas loadUI(Systeme systemeParam, String MODULEIDp) {
        if (!isUiLoaded) {
            systeme = systemeParam;
            MODULEID = MODULEIDp;
            cnvEmpty = systeme.getTabpaneTemplate(cnvEmpty);
            cnvEmpty.setID(MODULEID+"_CANVAS");
            cnvEmpty.addChild(getList());
            isUiLoaded = true;
        }
        return cnvEmpty;
    }

    public void buildList() {
        if (!isListBuild) {
            GRID_LIST = systeme.getGridTemplate(GRID_LIST);
            
            LIST_DS = new OrganisationListDS(systeme,MODULEID+"_LIST_DS",MODULEID);

            GRID_LIST.setDataSource(LIST_DS);
            
            GRID_LIST.setFields(getListGridFields());
            
            GRID_LIST.addCellDoubleClickHandler(new CellDoubleClickHandler() {
                public void onCellDoubleClick(CellDoubleClickEvent event) {
                    systeme.startLoading();
                    setListGridDoubleClickAction(event);
                }
            });
            
            
            GRID_LIST.addCellContextClickHandler(new CellContextClickHandler() {
                public void onCellContextClick(CellContextClickEvent event) {
                    systeme.startLoading();
                    itemId = event.getRecord().getAttributeAsInt(MODULEID+"_liste_id");
                }
            });
            
            GRID_LIST.setContextMenu(getMenuContexte());
            GRID_LIST.addCellClickHandler(new CellClickHandler() {
                public void onCellClick(CellClickEvent event) {
                    systeme.startLoading();
                    setListGridSingleClickAction(event);
                }
            });
            
            GRID_LIST.addFilterEditorSubmitHandler(new FilterEditorSubmitHandler() {
                public void onFilterEditorSubmit(FilterEditorSubmitEvent event) {
                    ResultSet rs = GRID_LIST.getResultSet();
                    rs.addDataArrivedHandler(new DataArrivedHandler() {
                        public void onDataArrived(DataArrivedEvent event) {
                            systeme.getAppBar().getTab(MODULEID).setTitle(systeme.getDictionary().MODULE_ORGANISATION_TITLE()+" ("+GRID_LIST.getResultSet().getLength()+")");
                        }
                    });
                }
            });

            isListBuild = true;

        }
        if (!isListFetch) {
            loadList();
            isListFetch = true;
        }        
    }

    public ListGrid getList() {
        if (!isListBuild) { buildList(); }
        return GRID_LIST;
    }

    public void loadList() {
    	if (!isListFetch) {
	        if (!isListBuild) { buildList(); }
	        GRID_LIST.invalidateCache();
	        GRID_LIST.fetchData();
	        isListFetch = true;
    	}
    	else {
    		systeme.stopLoading();
    	}
    }

    public void buildForm() {
        if (!isFormBuild) {
            FORM_EDIT = systeme.getFormTemplate(FORM_EDIT);
            
            FORM_EDIT.addItemKeyPressHandler(new ItemKeyPressHandler() {
                public void onItemKeyPress(ItemKeyPressEvent event) {
                    FORM_EDIT.getItem(MODULEID+"_form_changeHandler").setValue("true");
                }
            });
            FORM_DS = new OrganisationFormDS(MODULEID+"_FORM_DS",GRID_LIST,FORM_EDIT,systeme,MODULEID);
            FORM_EDIT.setDataSource(FORM_DS);

            FORM_EDIT.setFields(setFormFields());
            
            isFormBuild = true;
        }
    }
    
    public DynamicForm getForm() {
        if (!isFormBuild) { buildForm(); }
GWT.log("getForm:"+FORM_EDIT.getAutoFetchData());        
        return FORM_EDIT;
    }

    public void create(ListGridRecord record) {
        getForm().getItem(MODULEID+"_form_changeHandler").setValue("false");
        getForm().editNewRecord();
        getForm().clearErrors(true);
        getForm().getItem(MODULEID+"_form_id").setValue(0);
        Tab[] tabs = tabS_mini.getTabs();
        if (tabs != null) {
            for (int i = 0; i < tabs.length; i++) {
                tabs[i].setIcon("blank.png");
            }
        }      
        systeme.stopLoading();
    }

    public void loadForm(ListGridRecord record) {
        getForm().clearValues();
        getForm().clearErrors(Boolean.TRUE);
        String strId = record.getAttribute(MODULEID+"_liste_id");      
        getForm().fetchData(new Criteria("id",strId));
        isFormFetch = true;  
        Tab[] tabs = tabS_mini.getTabs();
        if (tabs != null) {
            for (int i = 0; i < tabs.length; i++) {
                tabs[i].setIcon("TabAdd.png");
            }
        }        
        systeme.getAppBar().updateTab(systeme.getAppBar().getTab(MODULEID),getForm());       
    }

    public DynamicForm showAndCreate(ListGridRecord record) {
        create(record);
        return getForm();
    }
    
    private ListGridField[] getListGridFields() {
    	ListGridField fldOrganisationId = new ListGridField();
        fldOrganisationId.setName(MODULEID+"_liste_id");
        fldOrganisationId.setTitle(" ");
        fldOrganisationId.setWidth(20);
        fldOrganisationId.setAlign(Alignment.LEFT);
        fldOrganisationId.setType(ListGridFieldType.TEXT);
        fldOrganisationId.setHidden(true);
        
        ListGridField fldOrganisationDescription = new ListGridField();
        fldOrganisationDescription.setName(MODULEID+"_liste_notes");
        fldOrganisationDescription.setTitle(" ");
        fldOrganisationDescription.setWidth(100);
        fldOrganisationDescription.setAlign(Alignment.LEFT);
        fldOrganisationDescription.setType(ListGridFieldType.TEXT);
        fldOrganisationDescription.setHidden(true);
        
        ListGridField fldfldOrganisationUrl = new ListGridField();
        fldfldOrganisationUrl.setName(MODULEID+"_liste_url");
        fldfldOrganisationUrl.setTitle(" ");
        fldfldOrganisationUrl.setWidth(100);
        fldfldOrganisationUrl.setAlign(Alignment.LEFT);
        fldfldOrganisationUrl.setType(ListGridFieldType.TEXT);
        fldfldOrganisationUrl.setHidden(true);
        
        ListGridField fldUrlIcon = new ListGridField();
        fldUrlIcon.setName(MODULEID+"_liste_urlIcon");
        fldUrlIcon.setTitle(" ");
        fldUrlIcon.setWidth(30);
        fldUrlIcon.setAlign(Alignment.CENTER);
        fldUrlIcon.setType(ListGridFieldType.IMAGE);
        fldUrlIcon.setImageURLPrefix("");
        fldUrlIcon.setImageURLSuffix(".png");
        
        ListGridField fldOrganisationName = new ListGridField();
        fldOrganisationName.setName(MODULEID+"_liste_name");
        fldOrganisationName.setTitle("Nom");
        fldOrganisationName.setWidth("*");
        fldOrganisationName.setAlign(Alignment.LEFT);
        fldOrganisationName.setType(ListGridFieldType.TEXT);
        fldOrganisationName.setHidden(Boolean.FALSE);
        fldOrganisationName.setShowHover(Boolean.TRUE);
        fldOrganisationName.setHoverCustomizer(new HoverCustomizer() {
            public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
                String strHover = "<table width=200><tr><td valign=top>notes: </td><td>"+record.getAttribute(MODULEID+"_liste_notes")+"</td></tr></table>";
                return strHover;
            }
        });
        
        ListGridField fldOrganisationType = new ListGridField();
        fldOrganisationType.setName(MODULEID+"_liste_type");
        fldOrganisationType.setTitle("Type");
        fldOrganisationType.setWidth(90);
        fldOrganisationType.setAlign(Alignment.LEFT);
        fldOrganisationType.setType(ListGridFieldType.TEXT);
        fldOrganisationType.setHidden(Boolean.FALSE);
        
        ListGridField fldOrganisationPhone = new ListGridField();
        fldOrganisationPhone.setName(MODULEID+"_liste_phone");
        fldOrganisationPhone.setTitle("Téléphone");
        fldOrganisationPhone.setWidth(100);
        fldOrganisationPhone.setAlign(Alignment.LEFT);
        fldOrganisationPhone.setType(ListGridFieldType.TEXT);
        fldOrganisationPhone.setHidden(Boolean.FALSE);
        
        ListGridField fldOrganisationAddress = new ListGridField();
        fldOrganisationAddress.setName(MODULEID+"_liste_address");
        fldOrganisationAddress.setTitle("Adresse");
        fldOrganisationAddress.setWidth(130);
        fldOrganisationAddress.setAlign(Alignment.LEFT);
        fldOrganisationAddress.setType(ListGridFieldType.TEXT);
        fldOrganisationAddress.setHidden(Boolean.FALSE);
        
        ListGridField fldOrganisationZipcode = new ListGridField();
        fldOrganisationZipcode.setName(MODULEID+"_liste_zipcode");
        fldOrganisationZipcode.setTitle("Code Postal");
        fldOrganisationZipcode.setWidth(80);
        fldOrganisationZipcode.setAlign(Alignment.LEFT);
        fldOrganisationZipcode.setType(ListGridFieldType.TEXT);
        fldOrganisationZipcode.setHidden(Boolean.FALSE);
        
        ListGridField fldOrganisationCity = new ListGridField();
        fldOrganisationCity.setName(MODULEID+"_liste_city");
        fldOrganisationCity.setTitle("Ville");
        fldOrganisationCity.setWidth(120);
        fldOrganisationCity.setAlign(Alignment.LEFT);
        fldOrganisationCity.setType(ListGridFieldType.TEXT);
        fldOrganisationCity.setHidden(Boolean.FALSE);
        
        ListGridField[] fields = {fldOrganisationId,fldOrganisationDescription,fldfldOrganisationUrl,fldUrlIcon,fldOrganisationName,fldOrganisationPhone,
                                    fldOrganisationAddress,fldOrganisationZipcode,fldOrganisationCity};
        
        return fields;
    }
    
    private com.smartgwt.client.widgets.form.fields.FormItem[] setFormFields() {
    	FORM_EDIT.setCellBorder(0);
        int NumCols = 7;
        FORM_EDIT.setNumCols(NumCols);
        FORM_EDIT.setColWidths(80,80,275,275,80,100,90);
        
        		StaticTextItem ID = new StaticTextItem();
        		ID.setTextBoxStyle("style_Text_Disabled_Medium");
        		ID.setShowTitle(Boolean.FALSE);
        		ID.setDefaultValue("#0000000");
        
                CanvasItem canvasCloseButton = new CanvasItem();
                canvasCloseButton.setColSpan(NumCols-1);
                canvasCloseButton.setWidth("100%");
                canvasCloseButton.setHeight(24);
                canvasCloseButton.setAlign(Alignment.RIGHT);
                canvasCloseButton.setShowTitle(Boolean.FALSE);
                    Img imgCloseButton = new Img("closeForm.png",22,22);
                    imgCloseButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
                        public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                            FORM_EDIT.clearErrors(Boolean.TRUE);
                            FORM_EDIT.clearValues();
                            systeme.getAppBar().updateTab(systeme.getAppBar().getTab(MODULEID),GRID_LIST);
                        }
                    });
                canvasCloseButton.setCanvas(imgCloseButton);
                
                HiddenItem hitChangeHandler = new HiddenItem(MODULEID+"_form_changeHandler");
                hitChangeHandler.setValue("false");
                
                HiddenItem hitId = new HiddenItem(MODULEID+"_form_id");
                
                final TextItem fitName = new TextItem();
                fitName.setName(MODULEID+"_form_name");
                fitName.setTitle("Nom");
                fitName.setWidth(400);
                fitName.setHeight(26);
                fitName.setColSpan(3);
                fitName.setRowSpan(1);
                fitName.setDefaultValue("");
                fitName.setTitleStyle("style_INPUTBOX_Default_Title");
                fitName.setTextBoxStyle("style_INPUTBOX_Default_Box");
                fitName.setRequired(Boolean.TRUE);
                                                
                TextAreaItem fitNote = new TextAreaItem();
                fitNote.setName(MODULEID+"_form_notes");
                fitNote.setTitle("Notes");
                fitNote.setWidth(470);
                fitNote.setHeight(133);
                fitNote.setRowSpan(3);
                fitNote.setColSpan(4);
                fitNote.setDefaultValue("");
                fitNote.setVAlign(VerticalAlignment.TOP);
                fitNote.setTitleStyle("style_INPUTBOX_Default_Title");
                fitNote.setTextBoxStyle("style_INPUTBOX_Default_Box");

                SelectItem sitType = new SelectItem();
                sitType.setName(MODULEID+"_form_type");
                sitType.setTitle("Type");
                sitType.setOptionDataSource(systeme.getOrganisationTypes(systeme));
                sitType.setValueField("type_id");
                sitType.setDisplayField("type_name");
                sitType.setWidth(400);
                sitType.setHeight(26);
                sitType.setRowSpan(1);
                sitType.setColSpan(3);
                sitType.setDefaultValue("");
                sitType.setTitleStyle("style_INPUTBOX_Default_Title");
                sitType.setTextBoxStyle("style_DROPBOX_Default_Box");
                
                SelectItem sitCategory = new SelectItem();
                sitCategory.setName(MODULEID+"_form_category");
                sitCategory.setTitle("Categorie");
                sitCategory.setOptionDataSource(systeme.getOrganisationCategories(systeme));
                sitCategory.setValueField("category_id");
                sitCategory.setDisplayField("category_name");
                sitCategory.setWidth(400);
                sitCategory.setHeight(26);
                sitCategory.setRowSpan(1);
                sitCategory.setColSpan(3);
                sitCategory.setDefaultValue("");
                sitCategory.setTitleStyle("style_INPUTBOX_Default_Title");
                sitCategory.setTextBoxStyle("style_DROPBOX_Default_Box");
                
                CanvasItem cniTabSet = new CanvasItem();
                cniTabSet.setTitle("");
                cniTabSet.setShowTitle(Boolean.FALSE);
                cniTabSet.setColSpan(NumCols);
                cniTabSet.setWidth("100%");
                cniTabSet.setHeight("*");
                cniTabSet.setAlign(Alignment.CENTER);
                                    	
                	tabS_mini.setAlign(Alignment.CENTER);
                	tabS_mini.setWidth("99%");
                    tabS_mini.setHeight("100%");
                    tabS_mini.setShowEdges(Boolean.FALSE);
                    tabS_mini.setPadding(0);
                    tabS_mini.setPaneMargin(0);
                    	
                	tabS_mini.setTabs(getTabMini());
                	                    
                cniTabSet.setCanvas(tabS_mini);

                SpacerItem pushDown = new SpacerItem();
                pushDown.setColSpan(NumCols);
                pushDown.setHeight(1);

                		Menu menuActionItems = new Menu();
                			MenuItem menuPrint = new MenuItem(systeme.getDictionary().PRINT());
                			MenuItem menuSend = new MenuItem(systeme.getDictionary().SEND());
                			MenuItem menuDuplicate = new MenuItem(systeme.getDictionary().DUPLICATE());
                			MenuItem menuDisable = new MenuItem(systeme.getDictionary().DISABLE());
                			MenuItem menuDelete = new MenuItem(systeme.getDictionary().DELETE());
                		menuActionItems.setItems(menuPrint,menuSend,menuDuplicate,menuDisable,menuDelete);
                		
	                MenuButton menuAction = new MenuButton(systeme.getDictionary().MENU_ACTION(), menuActionItems);
	                menuAction.setShowMenuBelow(Boolean.FALSE);
	                menuAction.setHeight(25);
                
                ToolbarItem tlbAction = new ToolbarItem();
                tlbAction.setButtons(menuAction);
                tlbAction.setColSpan(2);
                tlbAction.setStartRow(Boolean.TRUE);
                tlbAction.setEndRow(Boolean.FALSE);
                //tlbAction.setAlign(Alignment.CENTER);
                tlbAction.setWidth(80);
                tlbAction.setHeight(25);

                StaticTextItem stiCreatedDate = new StaticTextItem(MODULEID+"_form_created_date");
                stiCreatedDate.setShowTitle(Boolean.FALSE);
                stiCreatedDate.setColSpan(1);
                stiCreatedDate.setWidth(125);
                stiCreatedDate.setAlign(Alignment.RIGHT);
                stiCreatedDate.setTextBoxStyle("style_Text_Form_CreatedOn");
                stiCreatedDate.setDefaultValue("");

                StaticTextItem stiModifiedDate = new StaticTextItem(MODULEID+"_form_modified_date");
                stiModifiedDate.setShowTitle(Boolean.FALSE);
                stiModifiedDate.setColSpan(1);
                stiModifiedDate.setWidth(125);
                stiModifiedDate.setTextBoxStyle("style_Text_Form_CreatedOn");
                stiModifiedDate.setDefaultValue("");

                ButtonItem bitCancel = new ButtonItem(MODULEID+"_form_CANCEL", systeme.getDictionary().CANCEL());
                bitCancel.setWidth(75);
                bitCancel.setHeight(25);
                bitCancel.setColSpan(2);
                bitCancel.setAlign(Alignment.RIGHT);
                bitCancel.setStartRow(Boolean.FALSE);
                bitCancel.setEndRow(Boolean.FALSE);
                bitCancel.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
                    public void onClick(ClickEvent event) {
                        FORM_EDIT.clearErrors(Boolean.TRUE);
                        FORM_EDIT.clearValues();
                        systeme.getAppBar().updateTab(systeme.getAppBar().getTab(MODULEID),GRID_LIST);
                    }
                });

                SubmitItem sitSave = new SubmitItem(MODULEID+"_form_SAVE", systeme.getDictionary().SAVE());
                sitSave.setWidth(90);
                sitSave.setHeight(25);
                sitSave.setAlign(Alignment.CENTER);
                sitSave.setStartRow(Boolean.FALSE);
                sitSave.setEndRow(Boolean.TRUE);
                
                HiddenItem hitSaveOnExit = new HiddenItem(MODULEID+"_form_saveOnExit");
                hitSaveOnExit.setValue("false");

                com.smartgwt.client.widgets.form.fields.SpacerItem pushUp = new SpacerItem();
                pushUp.setColSpan(NumCols);
                pushUp.setHeight(10);
            
            com.smartgwt.client.widgets.form.fields.FormItem[] formFields = {ID,canvasCloseButton,fitName,fitNote,sitType,sitCategory,cniTabSet,pushDown,tlbAction,stiCreatedDate,stiModifiedDate,bitCancel,sitSave,pushUp,hitId,hitChangeHandler};
            
            FORM_EDIT.setAutoFocus(true);
            
            return formFields;
    }
    
    private void setListGridDoubleClickAction(CellDoubleClickEvent event) {
    	 systeme.startLoading();
         final ListGridRecord record = event.getRecord();
         loadForm(record);
    }
    
    private void setListGridSingleClickAction(CellClickEvent event) {
    	ListGridRecord record =  event.getRecord();
        int colNum = event.getColNum();
        String fieldName = GRID_LIST.getFieldName(colNum);
        if (fieldName.equals("organisation_liste_urlIcon")) {
            String strUrl = record.getAttribute("organisation_liste_url");
            if (strUrl != null) {
                if (strUrl.length() > 4) {
                    if (strUrl.indexOf("http") < 0) {
                        strUrl = "http://"+strUrl;
                    }
                    com.google.gwt.user.client.Window.open(strUrl,"url",null);
                }
                else {
                    SC.say(systeme.getDictionary().INVALID_URL());
                }
            }
            else {
                SC.say(systeme.getDictionary().INVALID_URL());
            }
        }
    }
    
    private Menu getMenuContexte() {
        Menu menuContextuel = new Menu();
        menuContextuel.setWidth(130);
            MenuItem menuItemOpen = new MenuItem(systeme.getDictionary().OPEN());
            menuItemOpen.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
                public void onClick(MenuItemClickEvent event) {
                    systeme.startLoading();
                    ListGridRecord recordToSend = new ListGridRecord();
                    recordToSend.setAttribute("product_liste_id",itemId);
                    loadForm(recordToSend);
                    systeme.getAppBar().updateTab(systeme.getAppBar().getTab("PRODUCTS"),getForm());
                }
            });
            MenuItem menuItemDelete = new MenuItem(systeme.getDictionary().DELETE());
            menuItemDelete.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
                public void onClick(MenuItemClickEvent event) {
                	SC.confirm(systeme.getDictionary().WINDOW_CONFIRM_TITLE(),systeme.getDictionary().CONFIRM_DELETE(), new BooleanCallback() {
                        public void execute(Boolean value) {
                            if (value) {
                                Record recordToDelete = new Record();
                                recordToDelete.setAttribute("product_liste_id",itemId);
                                GRID_LIST.removeData(recordToDelete);
                            }
                        }
                    });
                }
            });
            MenuItemSeparator separator = new MenuItemSeparator();
            MenuItem menuItemIsDone = new MenuItem(systeme.getDictionary().MODIFY());
            menuItemIsDone.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
                public void onClick(MenuItemClickEvent event) {
                    systeme.startLoading();
                    ListGridRecord recordToSend = new ListGridRecord();
                    recordToSend.setAttribute("product_liste_id",itemId);
                    loadForm(recordToSend);
                    systeme.getAppBar().updateTab(systeme.getAppBar().getTab(MODULEID),getForm());
                }
            });

        menuContextuel.addItem(menuItemOpen);
        menuContextuel.addItem(menuItemDelete);
        menuContextuel.addItem(separator);
        menuContextuel.addItem(menuItemIsDone);
        
        return menuContextuel;
    }
    
    private Tab[] getTabMini() {
    	Tab tabContacts = new Tab(systeme.getDictionary().TAB_MINI_CONTACTS_TITLE());
    	tabContacts.setID(systeme.getDictionary().TAB_MINI_CONTACTS_ID());
    	tabContacts.setIcon("TabAdd.png");
    	
    	Tab tabAddress = new Tab(systeme.getDictionary().TAB_MINI_ADDRESS_TITLE());
    	tabAddress.setID(systeme.getDictionary().TAB_MINI_ADDRESS_ID());
    	tabAddress.setIcon("TabAdd.png");
    	
    	Tab tabPhones = new Tab(systeme.getDictionary().TAB_MINI_PHONES_TITLE());
    	tabPhones.setID(systeme.getDictionary().TAB_MINI_PHONES_ID());
    	tabPhones.setIcon("TabAdd.png");
    	
    	Tab tabUrls = new Tab(systeme.getDictionary().TAB_MINI_URLS_TITLE());
    	tabUrls.setID(systeme.getDictionary().TAB_MINI_URLS_ID());
    	tabUrls.setIcon("TabAdd.png");
    	
    	Tab tabAttributs = new Tab(systeme.getDictionary().TAB_MINI_ATTRIBUTS_TITLE());
    	tabAttributs.setID(systeme.getDictionary().TAB_MINI_ATTRIBUTS_ID());
    	tabAttributs.setIcon("TabAdd.png");
    	
    	Tab[] tabs = {tabContacts,tabAddress,tabPhones,tabUrls,tabAttributs};
    	return tabs;
    }
        
}